﻿using System;
using BenchmarkDotNet.Attributes;
using SearchAlgorithms.Algorithms.Search;
using SearchAlgorithms.extension;
using SearchText;
using System.IO;
using X10D.Collections;

namespace SearchAlgorithmBenchmarks
{
    [Config(typeof(MyConfig))]
    [MemoryDiagnoser]

    [Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)]
    [RankColumn]

    public class SearcherBenchmarks
    {
//        private readonly byte[] master_bytes = new byte[] {
//    0xA1, 0xAC, 0x63, 0x4E, 0x4C, 0xB0, 0xD4, 0x22, 0x23, 0xB3, 0xC5, 0xFD, 0xF7, 0xDC, 0xFE, 0x10,
//    0x20, 0xB6, 0xAD, 0xA5, 0x6C, 0x37, 0xA7, 0x3E, 0x3E, 0x20, 0x48, 0x71, 0x70, 0xDF, 0x77, 0xCD,
//    0x49, 0x78, 0x63, 0x4E, 0x4C , 0x26, 0x34, 0xBD, 0xFD, 0x69, 0x80, 0x00, 0xC4, 0x89, 0x82, 0xE7,
//    0x4B, 0x47, 0xAD, 0x42, 0xB2, 0x11, 0x64, 0xC4, 0x96, 0xE7, 0x22, 0xD3, 0x9A, 0x8B, 0x7F, 0x4B,
//    0xDC, 0x05, 0x89, 0xD1, 0x60, 0xF5, 0xA2, 0x42, 0xC1, 0x63, 0x4E, 0x4C , 0x10, 0x7A, 0xA9, 0x11,
//    0x79, 0x55, 0x10, 0x4C, 0x5D, 0x67, 0xAD, 0xBA, 0x53, 0x05, 0x6C, 0x86, 0x69, 0x3F, 0xF1, 0x33,
//    0x1C, 0xEA, 0xC5, 0x23, 0xD1, 0x08, 0x24, 0x66, 0x08, 0x5C, 0x43, 0x8A, 0x0B, 0xC2, 0xD4, 0x30,
//    0x84, 0x66, 0xFC, 0x63, 0x4E, 0x4C , 0x34, 0xDC, 0x8D, 0x92, 0x3A, 0xDF, 0xA5, 0x01, 0x2C, 0x50,
//    0xAE, 0xC0, 0x13, 0xD5, 0xA3, 0x38, 0x63, 0x4E, 0x4C , 0x64
//};
//        private readonly byte[] search_bytes = new byte[] { 0x63, 0x4E, 0x4C };


        static string master_Path = "C:\\Users\\leomojys\\Desktop\\3.png";

        byte[] master_bytes = File.ReadAllBytes(master_Path);
        private readonly byte[] search_bytes = new byte[] {
            0x6C, 0xED, 0xED, 0x51, 0xDD, 0xAA, 0x43, 0x9C, 0xA1, 0x2A, 0x15, 0x6A, 0x2A, 0x66, 0x3B, 0xD7,
            0xE4, 0x8B, 0x05, 0xA6, 0x28, 0x58, 0x4C, 0xE7, 0xC4, 0x04, 0x14, 0x18, 0xA6, 0xF3, 0x39, 0xCB,
            0x7C, 0xC9, 0x24, 0x5F, 0x50, 0x5D, 0xCE, 0x68, 0xA6, 0x0B, 0x5A, 0xF9, 0x12, 0x8A, 0x0E, 0x71,
            0x9E, 0xA3, 0x34, 0x40, 0x00, 0x55, 0x1B, 0x64, 0x19, 0x0A, 0x08, 0x0B, 0x8C, 0x2A, 0x4A, 0x49,
            0x62, 0x8E, 0xC1, 0xA0, 0x29, 0xD0, 0xCA, 0x76, 0xF6, 0x5A, 0x6B, 0xAC, 0xE2, 0x8D, 0x5E, 0xAF,
            0xCF, 0xFF, 0xF1, 0x7F, 0xFC, 0x3F, 0xF9, 0x3F, 0xFF, 0xAF, 0xFF, 0x8B, 0xE5, 0x32, 0xB5, 0x7E
        };


        [Benchmark]
        public void Rubiksmaster02Search() => this.master_bytes.SingleSearch(this.search_bytes, Rubiksmaster02.Default);

        [Benchmark]
        public void Rubiksmaster02SearchSpan() => this.master_bytes.AsSpan().SingleSearch(this.search_bytes.AsSpan(), Rubiksmaster02.Default);

        [Benchmark]
        public void KMP() => this.master_bytes.SingleSearch(this.search_bytes, KMPSearch.Default);

        [Benchmark]
        public void KMPSpan() => this.master_bytes.AsSpan().SingleSearch(this.search_bytes.AsSpan(), KMPSearch.Default);

        [Benchmark]
        public void Brute() => this.master_bytes.SingleSearch(this.search_bytes, Brutesearch.Default);

        [Benchmark]
        public void BruteSpan() => this.master_bytes.AsSpan().SingleSearch(this.search_bytes.AsSpan(), Brutesearch.Default);


        [Benchmark]
        public void IndexOfSpan() => this.master_bytes.AsSpan().IndexOf(this.search_bytes.AsSpan());
    }
}